# -*- coding: utf-8 -*-
# @Time : 2023/10/28 19:09
# @Author : zxp

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('127.0.0.1', 8001))  # 监听
sock.listen(5)

while True:
    conn, addr = sock.accept()  # 等待连接，阻塞中
    print('有人连接')
    conn.sendall("欢迎进入智能客服服务".encode('utf-8'))

    while True:
        data = conn.recv(1024)  # 等待，接收信息
        if not data:
            break
        print(data.decode('utf-8'))
        conn.sendall("你在说啥？".encode('utf-8'))
    print("断开连接了")
    conn.close()  # 关闭连接

sock.close()
